//
//  Person.m
//  OC2_实例变量可见度_方法
//
//  Created by Scott on 16/4/19.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "Person.h"

@implementation Person


#pragma mark - Creating and Init


+ (instancetype)personWith:(NSString *)name
                       sex:(NSString *)sex
                       age:(NSInteger)age {
    
    return [[Person alloc] initWithName:name sex:sex age:age];
    
}

- (instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age {
    
    // 对象执行父类的init方法
    self = [super init];
    
    if (self) {
        // 实例变量赋值
        _name = name;
        _sex = sex;
        _age = age;
    }
    
    return self;
}



- (instancetype)initWithName:(NSString *)name {
    
    return [self initWithName:name sex:nil age:0];
    
}

#pragma mark - setter, getter

- (void)setName:(NSString *)name {
    _name = name;
}
- (NSString *)name {
    return _name;
}

- (void)setSex:(NSString *)sex {
    _sex = sex;
}
- (NSString *)sex {
    return _sex;
}

- (void)setAge:(NSInteger)age {
    _age = age;
}
- (NSInteger)age {
    return _age;
}



#pragma mark - other
// 给_sex实例变量赋值的方法.
// 方法名: setterSex:
- (void)setterSex:(NSString *)sex {
    
    _sex = sex;

}

// 写一个取出_sex实例变量值的方法
- (NSString *)getSex {
    
    return _sex;
    
}

// 同时给_name, _sex, _age实例变量赋值
// 方法名: setName:setSex:setAge:
- (void)setName:(NSString *)name setSex:(NSString *)sex setAge:(NSInteger)age {
    
    _name = name;
    _sex = sex;
    _age = age;
}

@end

